//go:build ignore

package main

import (
	"encoding/json"
	"fmt"
	"github.com/gomodule/redigo/redis"
)

func main() {
	c, err := redis.Dial("tcp", "8.142.102.189:6379")
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	type User struct {
		Name  string `json:"name"`
		Phone string `json:"phone"`
	}

	user := User{Phone: "123", Name: "lwz"}
	marshal, err := json.Marshal(&user)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	reply, e := c.Do("set", "lwz", marshal)
	if e != nil {
		fmt.Println(e.Error())
		return
	}
	fmt.Println(reply)
	strings, err := redis.String(c.Do("get", "lwz"))
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	u := User{}
	err = json.Unmarshal([]byte(strings), &u)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Println(u.Phone, u.Name)

	defer c.Close()
}
